package cn.yll.api.order.service;

import cn.yll.common.module.PageModel;
import cn.yll.common.module.PageRequest;
import cn.yll.common.module.RestModel;
import cn.yll.api.order.request.OrderRequest;
import cn.yll.api.order.response.GoodResponse;
import cn.yll.common.exception.BsErrEnum;
import cn.yll.common.exception.BsException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
 * 服务降级处理类
 * @author yangll
 */
@Slf4j
@Component
public class RemoteGoodFeinServiceImpl implements FallbackFactory<RemoteGoodFeinService> {

    @Override
    public RemoteGoodFeinService create(Throwable cause) {
        log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + "~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
        return new RemoteGoodFeinService() {
            @Override
            public RestModel<PageModel<GoodResponse>> findGoodsByPage(PageRequest request) {
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<?> checkPriceAndReduceNum(OrderRequest request) {
                throw new BsException(BsErrEnum.RPC_ERROR);
            }
        };
    }
}
